//
//  IntelligentResultViewController.m
//  HarmonizePub
//
//  Created by Haven on 16/10/14.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "IntelligentResultViewController.h"
#import "GuideDiagnose.h"
#import "Config.h"
#import "SchedulingController.h"
#import "AppointmentController.h"

@interface IntelligentResultViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewConstraintHeight;
@property (nonatomic, strong) NSArray *dpArr;

@property (nonatomic, strong) NSArray *depListsArray;

@end

@implementation IntelligentResultViewController

- (NSArray *)depListsArray
{
    if (_depListsArray == nil) {
        _depListsArray = [[NSArray alloc] init];
    }
    return _depListsArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.title = @"自测结果";
    self.textView.text = self.guideDiagnose.diagnoseContent;
   
    // 获取就诊科室列表
    NSArray *tempArr = [self.guideDiagnose.dpList componentsSeparatedByString:@","];
    NSMutableArray *temp = [[NSMutableArray alloc] init];
    for (NSString *str in tempArr) {
        if (str.length != 0) {
            [temp addObject:str];
        }
    }
    self.dpArr = temp;
    [self.tableView reloadData];
    
    // 获取预约挂号科室列表
    [self getDepList];
   
}

// 获取预约挂号科室列表
- (void)getDepList {
    [HTTPSTool GETRequestWithPath:XHGetOrderDpPath params:nil success:^(NSDictionary * _Nonnull JSON) {
         self.depListsArray = JSON[@"data"][@"list"];
//        NSLog(@"%@", self.depListsArray);
    }];
}



#pragma mark -- UITableViewDelegate / UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dpArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSString *resultStr = self.dpArr[indexPath.row];
    
    cell.textLabel.text = resultStr;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *rowStr = self.dpArr[indexPath.row];
    NSDictionary *dictTemp;
    for (NSDictionary *dict in self.depListsArray) {
        if ([rowStr isEqualToString: dict[@"ksmc"]])
            dictTemp = dict;
    }
    if (dictTemp) {
        SchedulingController *scheduling = [[SchedulingController alloc] init];
        scheduling.selectDataDict = dictTemp;
        [self.navigationController pushViewController:scheduling animated:YES];
    }else{
        AppointmentController *appointmentController =[[AppointmentController alloc] init];
        appointmentController.title = @"预约挂号";
        [self.navigationController pushViewController: appointmentController animated:YES];
    }
}
@end
